package app.com.business.service.impl;

import java.util.List;

import org.springframework.orm.hibernate3.HibernateObjectRetrievalFailureException;

import app.com.business.bo.AffectationDepartement;
import app.com.business.bo.Prof;
import app.com.business.bo.Salle;
import app.com.business.dao.AffectationDao;
import app.com.business.dao.ProfDao;
import app.com.business.dao.SalleDao;
import app.com.business.exceptions.AffectationException;
import app.com.business.exceptions.MaterielException;
import app.com.business.service.GestionAffectation;

public class GestionAffectationImpl implements GestionAffectation{

	
	private AffectationDao affectationDao;
	private SalleDao salleDao;
	private ProfDao profDao;
	
	public void createLocation(AffectationDepartement affectation)
			throws AffectationException {
		try {
			affectationDao.create(affectation);
		} catch (HibernateObjectRetrievalFailureException e) {
			throw new AffectationException(e.getMessage() , e.getCause());
		}
		
		
	}

	public void createResponsable(Prof responsable) throws AffectationException {
		try {
			profDao.create(responsable);
		} catch (HibernateObjectRetrievalFailureException e) {
			throw new AffectationException(e.getMessage() , e.getCause());
		}
		
	}

	public void createSalleBureau(Salle salleBureau)
			throws AffectationException {
		try {
			salleDao.create(salleBureau);
		} catch (HibernateObjectRetrievalFailureException e) {
			throw new AffectationException(e.getMessage() , e.getCause());
		}
		
	}

	
	public void deleteLocation(String codeAffectation)
			throws AffectationException, MaterielException {
		try {
			affectationDao.delete(affectationDao.getAffectationByCodeAffectation(codeAffectation).getIdAffectation());
		} catch (HibernateObjectRetrievalFailureException e) {
			throw new AffectationException(e.getMessage() , e.getCause());
		}
		
		
	}

	public void deleteResponsable(String codeResponsable)
			throws AffectationException, MaterielException {
		try {
			profDao.delete(profDao.getProfByCodeProf(codeResponsable).getIdProf());
		} catch (HibernateObjectRetrievalFailureException e) {
			throw new AffectationException(e.getMessage() , e.getCause());
		}
		
	}

	public void deleteSalleBureau(String codeSalleBureau)
			throws AffectationException, MaterielException {
		try {
			salleDao.delete(salleDao.getSalleByCodeSalle(codeSalleBureau).getIdSalle());
		} catch (HibernateObjectRetrievalFailureException e) {
			throw new AffectationException(e.getMessage() , e.getCause());
		}
		
	}
	

	public List<AffectationDepartement> getAllAffectations() {
		return affectationDao.getAll();
	}

	public List<Salle> getAllSalles() {
		return salleDao.getAllDistinct();
	}

	public List<Prof> getAllProfs() {
		return profDao.getAll();
	}
	
	public AffectationDao getAffectationDao() {
		return affectationDao;
	}

	public void setAffectationDao(AffectationDao affectationDao) {
		this.affectationDao = affectationDao;
	}

	public SalleDao getSalleDao() {
		return salleDao;
	}

	public void setSalleDao(SalleDao salleDao) {
		this.salleDao = salleDao;
	}

	public ProfDao getProfDao() {
		return profDao;
	}

	public void setProfDao(ProfDao profDao) {
		this.profDao = profDao;
	}

	

}
